package cn.com.zhuxulin.android.demos.activities;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import cn.com.zhuxulin.android.demos.R;

public class NotificationDemos extends Activity {
	private Notification notifi = null;
	private NotificationManager manager = null;
	private TextView view = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.notification);
		view = (TextView) findViewById(R.id.notification);
		view.setText("Click to send a notification");
		manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
		notifi = new Notification(R.drawable.icon, "I am a notification",
				System.currentTimeMillis());
		notifi.flags = Notification.FLAG_AUTO_CANCEL;

		Intent intent = new Intent(this, NotificationDemos.class);
		// setFlags:Control how this activity start such as sign top ...
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
				| Intent.FLAG_ACTIVITY_NEW_TASK);

		PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
				PendingIntent.FLAG_UPDATE_CURRENT);
		notifi.setLatestEventInfo(this, "Test Notification",
				"This is a notification demo", pIntent);
		view.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				manager.notify(0, notifi);
			}
		});
	}
}
